package org.shortlink.admin.controller;

import lombok.RequiredArgsConstructor;
import org.shortlink.admin.common.convention.result.Result;
import org.shortlink.admin.common.enums.UserErrorCodeEnum;
import org.shortlink.admin.dto.resp.UserRespDTO;
import org.shortlink.admin.service.IUserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户管理控制层
 */
@RestController
@RequiredArgsConstructor    //该注释能自动注入final修饰的字段
public class UserController {
    private final IUserService userService;

    /**
     *根据用户名查询用户信息
     */
    @GetMapping("/api/shortlink/v1/user/{username}")
    public Result<UserRespDTO> getUserByUsername(@PathVariable("username") String username){
        UserRespDTO userRespDTO = userService.selectUserByName(username);
        if(userRespDTO == null){
            return new Result<UserRespDTO>().setCode(UserErrorCodeEnum.USER_NULL.code()).setMessage("用户查询为空");
        }else {
            return new Result<UserRespDTO>().setCode("0").setData(userRespDTO);
        }
    }
}
